#include "GS_Splash.h"
#include "GameCore\Device_Base.h"
#include "GameCore\Game.h"
#include "GS_Play.h"

void GS_Splash::Init()
{
	camera = new Camera();

	camera->SetCameraLookAt(0.0f, 0.0f, 50.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

	Device_Base::GetInstance()->SetProjectionOrthoCenterMatrix(Device_Base::GetInstance()->GetWidth()
		, Device_Base::GetInstance()->GetHeight(), 0.01f, 100.0f);

	simpleProgram = ShaderManager::GetInstance()->GetProgramFromFile("2D_vs.txt", "2D_fs.txt");

	//fireworkProgram = ShaderManager::GetInstance()->GetProgramFromFile("sdcard/firework_vs.txt", "sdcard/firework_fs.txt");

	spotTexture = TextureManager::GetInstance()->LoadTexture("spot.tga");

	spriteDog = SpriteManager::GetInstance()->LoadSpriteFromXMLFile("dog.sprite");

	dog = new GameObject2D();
	dog->SetSprite(spriteDog);
	dog->SetAnim(spriteDog->GetAnim(0));
	dog->EnableAnim(true);

	Device_Base::GetInstance()->SetClearColorBuffer(0.0f, 0.0f, 0.0f, 1.0f);

}
void GS_Splash::Release()
{
	SafeDelete(camera);
}
void GS_Splash::Update(float timeTotal, float timeDelta)
{
	static float delay = 0.0f;
	dog->Update(timeDelta);
	delay += timeDelta;
	if (delay > 1.0f)
	{
		Game::GetInstance()->SwitchState(new GS_Play());
	}
}
void GS_Splash::Render()
{
	Device_Base::GetInstance()->ClearColorDepthStencilBuffer(true, false, false);
	Device_Base::GetInstance()->UseProgram(simpleProgram);
	//Device_Base::GetInstance()->SetCameraActivated(camera);
	Device_Base::GetInstance()->BeginDraw2DLogical();
	BlendState blendState;
	Device_Base::GetInstance()->SetBlendState(blendState);
	Device_Base::GetInstance()->EnableBlend();
	dog->SetPosition(0.5f, 0.0f);
	dog->Render();
	Device_Base::GetInstance()->EndDraw2D();
}